package com.zzyl.controller.manager;

import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.dto.NursingPlanPageQueryDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理")
@Slf4j
public class NursingPlanController {

    @Autowired
    NursingPlanService nursingPlanService;

    /**
     * 获取所有护理计划
     * @return
     */
    @ApiOperation("获取所有护理计划")
    @GetMapping
    ResponseResult<List<NursingPlanVo>> getNursingPlanVoList() {
        List<NursingPlanVo> list = nursingPlanService.list();
        return ResponseResult.success(list);
    }

    /**
     * 新增护理计划
     * @param nursingPlanDto
     * @return
     */
    @ApiOperation("新增护理计划")
    @PostMapping
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        log.info("新增护理计划:{}", nursingPlanDto);
        nursingPlanService.addNursingPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    /**
     * 条件分页查询护理计划
     * @param dto
     * @return
     */
    @ApiOperation("条件分页查询护理计划")
    @GetMapping("/search")
    public ResponseResult<PageBean<NursingPlanVo>> searchNursingPlan(NursingPlanPageQueryDto dto) {
        log.info("条件分页查询护理计划:{}", dto);
        PageBean<NursingPlanVo> pageBean = nursingPlanService.searchNursingPlan(dto);
        return ResponseResult.success(pageBean);
    }

    /**
     * 根据id查询护理计划
     * @param id
     * @return
     */
    @ApiOperation("根据id查询护理计划")
    @GetMapping("/{id}")
    public ResponseResult<NursingPlanVo> getNursingPlanById(@PathVariable Long id) {
        log.info("根据id查询护理计划:{}", id);
        NursingPlanVo nursingPlanVo = nursingPlanService.getNursingPlanById(id);
        return ResponseResult.success(nursingPlanVo);
    }

    /**
     * 修改护理计划
     * @param id
     * @param nursingPlanDto
     * @return
     */
    @ApiOperation("修改护理计划")
    @PutMapping("/{id}")
    public ResponseResult updateNursingPlan(@PathVariable Long id, @RequestBody NursingPlanDto nursingPlanDto) {
        log.info("修改护理计划，id:{}，内容:{}", id, nursingPlanDto);
        nursingPlanDto.setId(id);
        nursingPlanService.updateNursingPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    /**
     * 删除护理计划
     * @param id
     * @return
     */
    @ApiOperation("删除护理计划")
    @DeleteMapping("/{id}")
    public ResponseResult deleteNursingPlan(@PathVariable Long id) {
        log.info("删除护理计划:{}", id);
        nursingPlanService.deleteNursingPlan(id);
        return ResponseResult.success();
    }

    /**
     * 启用禁用护理计划
     * @param id
     * @param status
     * @return
     */
    @ApiOperation("启用禁用护理计划")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult enableOrDisableNursingPlan(@PathVariable Long id, @PathVariable Integer status) {
        log.info("启用禁用护理计划，id:{}，status:{}", id, status);
        nursingPlanService.enableOrDisableNursingPlan(id, status);
        return ResponseResult.success();
    }
}
